package com.gmall.rabbitmq.consumer.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class RabbitMQServive_Delay {

    @RabbitHandler
    @RabbitListener(queues = "Queue_Delay_1")
    public void receive_SimpleMessage2(Channel channal, Message message,String msg) throws IOException {
        try {
            long deliveryTag = message.getMessageProperties().getDeliveryTag();
            System.out.println("------ Queue_Delay_1 Start-------");
            System.out.println("MessageID:" + message.getMessageProperties().getMessageId());
            System.out.println("MessageBody:" + new String(message.getBody()));
            System.out.println("msg:" + msg);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("====>" + simpleDateFormat.format(new Date()));
            System.out.println("------ Queue_Delay_1 End-------");

            channal.basicAck(deliveryTag, false);//手动确认，告诉MQ，我收到了，你可以删掉
        }catch (Exception e){

        }
    }

}
